package com.genesis.yunnanji.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.genesis.yunnanji.R;
import com.genesis.yunnanji.utils.AndroidWorkaround;
import com.genesis.yunnanji.utils.GenesisUtils;
import com.genesis.yunnanji.utils.UpdateUtils;
import com.genesis.yunnanji.view.DataLoadingDialog;
import com.jaeger.library.StatusBarUtil;
import com.umeng.analytics.MobclickAgent;

import org.xutils.x;

public abstract class BaseActivity extends AppCompatActivity {
    public Context context;
    public GenesisUtils genesisUtils;
    public UpdateUtils updateUtils;
    public DataLoadingDialog dialog;
    public View shade;
    public View nodata;

    protected void onCreate(Bundle savedInstanceState, int layoutId) {
        super.onCreate(savedInstanceState);

        setContentView(layoutId);
        AndroidWorkaround.assistActivity(findViewById(android.R.id.content));
        x.view().inject(this);

        if (findViewById(R.id.layout_shade) != null) {
            shade = findViewById(R.id.layout_shade);
        }
        if (findViewById(R.id.layout_nodata) != null) {
            nodata = findViewById(R.id.layout_nodata);
        }

        StatusBarUtil.setColor(this, getResources().getColor(R.color.divider), 50);

        context = this;
        dialog = new DataLoadingDialog(context);
        dialog.setCanceledOnTouchOutside(false);
        initUtils();
        initView(savedInstanceState);
        setUpView();

    }


    protected abstract void initView(Bundle savedInstanceState);

    protected abstract void setUpView();

    private void initUtils() {
        genesisUtils = GenesisUtils.getIntance();
        genesisUtils.init(context);
    }


    private void initTitle() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        context = null;
        genesisUtils = null;
        dialog = null;
        shade = null;
        nodata = null;
        System.gc();
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }
    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

}
